<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mod_categories extends CI_Controller {
    function  __construct(){
        parent::__construct();
       
    }
    function index($table){
       // get all category ->menu
        $dat = $this->common_model->getdata($table,array('publish'=>1),array('id','parentid','title','alias'));
        if($dat){
            foreach ( $dat as $v){
                $data[$v->parentid][]=$v;
            }
            $this->menucreat($data,0);
        $this->load->view('mod_categories/mod_categories' ,array('category'=>$this->menu));
        }   
    }
    function menucreat($data,$id=0){        
        if($id==0){ 
            $this->menu .= '<ul id="browser" class="box_content block">';}else $this->menu .= '<ul>';
        foreach ($data[$id] as $dulieu ){
            $this->menu .='<li>';
            $this->menu .='<h2><a title="'.$dulieu->title.'" href="'.base_url().$dulieu->alias.'.1.html">'.$dulieu->title.'</a></h2>';
            if(!empty($data[$dulieu->id])){
                $this->menucreat($data,$dulieu->id);
            }
            $this->menu .='</li>';
        }
        $this->menu .='</ul>';
        
    }
    function getmenu_tl(){
        $data = $this->common_model->getdata('article_category',array('publish'=>1),array('id','title','alias','position'),array('order','ASC'));
        if(!empty($data)){
            $top=$left='';
            foreach($data as $data){
                if($data->position==1){
                    $top.='<li><a href="'.base_url().$data->alias.'.0.html"><h2>'.$data->title.'</h2></a></li>';
                }else{
                    $left.='<li><h2><a href="'.base_url().$data->alias.'.0.html">'.$data->title.'</a></h2></li>';
                }
            }
            return array('top'=>$top,'left'=>$left);
        }else return false;
    }
    
}